<extend name="default/template/mybase2" />

<block name="head">
    <link rel="stylesheet" href="__CSS__/exLog2.css" />
</block>

<block name="body">
<div class="page-group">
<div id="page-infinite" class="page">
  <div class="content infinite-scroll" data-distance="100">


    <div class="list-block" id="list">
      
      <!-- <ul class="list-container"></ul> -->
    </div>
    <!-- 加载提示符 -->
    <div class="infinite-scroll-preloader"><div class="preloader"></div></div>
  </div>
</div>
</div>
</block>

<block name="foot">
<script>
  $(function() {
  'use strict';
  $(document).on("pageInit", "#page-infinite", function(e, id, page) {
  console.log('indexpageinit');
    // var lastIndex = $('.list-container li').length;
    var lastIndex = $('#list>.card').length;
    var loading = false;
    // 最多可加载的条目
    var maxItems = 500;
    var itemsPerLoad = 10;
    // alert(lastIndex);
    addItems(itemsPerLoad, lastIndex);
    function addItems(number, lastIndex) {
       $.getJSON("{:U('ExchangeLog/getLogs',array('uid'=>$uid,'psw'=>$psw),false)}",{ 'start':lastIndex,'size':number },function(data){
          // $.alert(data.info);
            console.log('getjson...');
          if(!data.status){$.alert(data.info);return;}
          if(!data.info || data.info.length < number){
            $.toast('没有更多了');$('.infinite-scroll-preloader').remove();
            $.detachInfiniteScroll($('.infinite-scroll'));
            // return;
          }
          var html = '',infos =data.info;
          console.log('infos:',infos);
          $.each(infos,function(i,v){
            html = html + '<div class="content-block-title">'+v.exchange_time+'</div>'
      +'<div class="card">'
      +'  <div class="card-content">'
      +'    <div class="list-block media-list">'
      +'<ul><li class="item-content">'
          +'<div class="item-media"><a target="_self" data-no-cache="true" href="{:U(\'Webview/ExchangeLog/detail\',array(\'uid\'=>$uid,\'psw\'=>$psw),\'\')}/id/'+v.id+'"><img src="{:U(\'Api/Picture/index\')}?id='+v.main_img+'" width=80 height=80 /></a></div>'
      +'  <div class="item-inner">'
      +'    <div class="item-title-row">'
      +'        <div class="item-title">'+v.pname+'</div>'
      +'    </div>'
      +'    <div class="item-subtitle"><span class="left">'+v.price+'元</span><span class="right">'+v.excahnge_status+'</span></div>'
      +'</div></li></ul>'
      +'  </div></div>'
      +'<div class="card-footer"><span></span><a target="_self" data-no-cache="true" href="{:U(\'Webview/ExchangeLog/detail\',array(\'uid\'=>$uid,\'psw\'=>$psw),\'\')}/id/'+v.id+'">查看详情 <span class="icon icon-right"></span></a></div>'
      +'</div>';
            // html =html + '<li><div class="time"></div>'
            //   +'<div>'
            //   +'    <div class="img"><a target="_self" data-no-cache="true" href="{:U(\'Webview/ExchangeLog/detail\',array(\'uid\'=>$uid,\'psw\'=>$psw),\'\')}/id/'+v.id+'"><img src="{:U('Api/Picture/index')}?id='+v.main_img+'" width=80 height=80 /></a></div>'
            //   +'    <div class="con">'
            //   +'        <div class="th">'+v.pname+'</div>'
            //   +'        <div class="bd clearfix"><div class="left">'+v.price+'元</div><div class="right">'+v.excahnge_status+'</div></div></div>'
            //   +'</div>'
            //   +'<div class="text-r"><a target="_self" data-no-cache="true" href="{:U(\'Webview/ExchangeLog/detail\',array(\'uid\'=>$uid,\'psw\'=>$psw),\'\')}/id/'+v.id+'">查看详情 <span class="icon icon-right"></span></a></div>'
            //   +'</li>';
          });
          // 添加新条目
          $('.infinite-scroll .list-block').append(html);
          // $.detachInfiniteScroll($('.infinite-scroll'));
            // 删除加载提示符
          // $('.infinite-scroll-preloader').remove();
          $.refreshScroller();
      })
    }
    // 注册'infinite'事件处理函数
    $(page).on('infinite', function() {
      console.log('infinate');
      if (loading) return;
      loading = true;
      setTimeout(function() {
          loading = false;
          // if (lastIndex >= maxItems) {
          //     $.detachInfiniteScroll($('.infinite-scroll'));
          //     $('.infinite-scroll-preloader').remove();
          //     return;
          // }
          addItems(itemsPerLoad, lastIndex);
          // lastIndex = $('.list-container .card').length;
          lastIndex = $('#list>.card').length;
          $.refreshScroller();
      }, 1000);
    });
  });
  $.init();
});
</script>
</block>